package sample;

import com.jfoenix.controls.*;
import com.jfoenix.skins.JFXTableColumnHeader;
import com.jfoenix.skins.JFXTreeTableViewSkin;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.scene.Scene;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.io.InputStream;

public class Main extends Application {
    private Stage stage;
    @Override
    public void start(Stage primaryStage) throws Exception{
        primaryStage.setResizable(false);
        primaryStage.setTitle("全国气象年数据服务");
//        primaryStage.initStyle(StageStyle.UNIFIED);
        stage = primaryStage;
        loginpage();
        stage.show();
//
//        JFXTextField field = new JFXTextField("hello world");
//        JFXButton jfxButton = new JFXButton("jbutton");
//        AnchorPane.setTopAnchor(jfxButton,100.0);
//        stage.setHeight(500);
//        stage.setWidth(500);
//        JFXTreeCell jfxTreeCell = new JFXTreeCell();
//        TreeItem item = new TreeItem("hanka");
//        JFXTreeView jfxTreeView  = new JFXTreeView(item);
//        JFXListView jfxListView = new JFXListView();
//        JFXListCell jfxListCell =  new JFXListCell();
//        AnchorPane anchorPane = new AnchorPane();
//        TreeTableView treeTableView = new TreeTableView();
//        JFXTreeTableView jfxTreeView = new JFXTreeTableView();
//        jfxTreeView.group(new TreeTableColumn("姓名"),new TreeTableColumn("性别"),new TreeTableColumn("班级"));
//        jfxTreeView.setCurrentItemsCount(3);
//        TreeTableColumn name = new TreeTableColumn("name");
//        jfxTreeView.setTreeColumn(name);
//        TreeTableColumn sex = new TreeTableColumn("sex");
//        jfxTreeView.setTreeColumn(sex);
//        TreeTableColumn aClass = new TreeTableColumn("class");
//        jfxTreeView.setTreeColumn(aClass);
////        anchorPane.getChildren().addAll(jfxTreeView);
//        JFXProgressBar jfxProgressBar = new JFXProgressBar();
//        JFXAlert jfxAlert = new JFXAlert();
//        jfxAlert.setContent(jfxProgressBar);
//        JFXButton jfxButton = new JFXButton("ss");
//        jfxButton.setOnAction(event -> jfxAlert.showAndWait());
//        anchorPane.getChildren().addAll(jfxButton);
//        stage.setScene(new Scene(anchorPane));

    }


    public static void main(String[] args) {
        launch(Main.class,args);
    }

    public void loginpage() throws Exception {
        sample.Controller con = (sample.Controller) replaceSceneContent("/fxml/login.fxml");
        con.setApplication(this);
    }

    public void mainPage(String role) throws Exception {
        sample.MainController con = (sample.MainController)replaceSceneContent("/fxml/shouye.fxml");
        con.initilalize(role);
    }

    private Initializable replaceSceneContent(String fxml) throws Exception {
        FXMLLoader loader = new FXMLLoader();
        InputStream in = Main.class.getResourceAsStream(fxml);
        loader.setBuilderFactory(new JavaFXBuilderFactory());
        loader.setLocation(Main.class.getResource(fxml));
        AnchorPane root;
        try {
            root = loader.load(in);
        } finally {
            in.close();
        }
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.sizeToScene();
        return (Initializable) loader.getController();
    }


}
